﻿using ASP;
using System;
using System.Configuration;
using System.Drawing;
using System.Globalization;
using System.Threading;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Resources;
public partial class Reminder : Page, IRequiresSessionState
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ((Label)this.Master.FindControl("lblMstTitle")).Text = "| " + ISitemap.ProjectReminder.ToString();
        }
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        this.Sort(e, this.GridView1);
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = ((this.GridView1.PageIndex * 10) + (e.Row.RowIndex + 1)).ToString();
            if (e.Row.Cells[11].Text == "1")
            {
                //e.Row.ForeColor = ColorTranslator.FromHtml("#000000");
                //e.Row.BackColor = ColorTranslator.FromHtml("#FFCC99");
            }
            e.Row.Cells[11].Text = "";
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    }

    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        this.Redirect(this.GridView1);
    }

    protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
    {
        this.Sort(e, this.GridView2);
    }

    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = ((this.GridView2.PageIndex * 10) + (e.Row.RowIndex + 1)).ToString();
            if (e.Row.Cells[12].Text == "1")
            {
                //e.Row.ForeColor = ColorTranslator.FromHtml("#000000");
                //e.Row.BackColor = ColorTranslator.FromHtml("#FFCC99");
            }
            e.Row.Cells[12].Text = "";
        }
    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string projectGroupId = this.GridView2.DataKeys[this.GridView2.SelectedIndex].Values["ProjectGroupID"].ToString();
        string projectCode = this.GridView2.DataKeys[this.GridView2.SelectedIndex].Values["ProjectCode"].ToString();
        string projectType = this.GridView2.DataKeys[this.GridView2.SelectedIndex].Values["Type"].ToString();
        this.Session["fromReminder"] = "1";
        base.Response.Redirect("Default.aspx?projectGroupId=" + projectGroupId.ToString() + "&projectCode=" + projectCode.ToString() + "&projectType=" + projectType.ToString());
    }

    protected void GridView2_SelectedIndexChanged1(object sender, EventArgs e)
    {
        this.Redirect(this.GridView2);
    }

    protected override void InitializeCulture()
    {
        string sCulture = ConfigurationManager.AppSettings["DefaultCulture"].ToString();
        try
        {
            sCulture = this.Session["Culture"].ToString();
        }
        catch (NullReferenceException)
        {
        }
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sCulture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(sCulture);
        base.InitializeCulture();
    }

    private void Redirect(GridView gv)
    {
        string projectGroupId = gv.DataKeys[gv.SelectedIndex].Values["ProjectGroupId"].ToString();
        string projectCode = gv.DataKeys[gv.SelectedIndex].Values["ProjectCode"].ToString();
        string projectType = gv.DataKeys[gv.SelectedIndex].Values["Type"].ToString();
        this.Session["fromReminder"] = "1";
        base.Response.Redirect("Default.aspx?projectGroupId=" + projectGroupId.ToString() + "&projectCode=" + projectCode.ToString() + "&projectType=" + projectType.ToString() + "&np=0");
    }

    protected void Sort(GridViewRowEventArgs e, GridView gv)
    {
        if ((e.Row != null) && (e.Row.RowType == DataControlRowType.Header))
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                if (cell.HasControls())
                {
                    LinkButton button = (LinkButton)cell.Controls[0];
                    if (button != null)
                    {
                        System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
                        image.ImageUrl = "";
                        if (gv.SortExpression == button.CommandArgument)
                        {
                            if (gv.SortDirection == SortDirection.Ascending)
                            {
                                image.ImageUrl = "images/sortup.gif";
                            }
                            else
                            {
                                image.ImageUrl = "images/sortdown.gif";
                            }
                        }
                        if (image.ImageUrl != "")
                        {
                            cell.Controls.Add(image);
                        }
                    }
                }
            }
        }
    }
}
